import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    host: '0.0.0.0', // 解决不能通过ip访问
    port: 8089,
    cors: true,
    proxy: {
      '/glgis-sdk': {
        // target: 'http://10.226.122.22:7070/', //现场
        target: 'http://111.229.73.147:30012/', //本地
        changeOrigin: true,
        rewrite: path => path.replace(/^\/glgis-sdk/, '/glgis-sdk')
      },
      '/raw': {
        target: 'http://10.226.107.36:9090/', //现场
        // target: 'http://101.126.153.10:9090/', //本地
        changeOrigin: true,
        rewrite: path => path.replace(/^\/raw/, '/raw')
      },
      '/analysis': {
        target: 'http://10.226.107.37:8089/', //现场
        // target: 'http://101.126.153.10:9090/', //本地
        changeOrigin: true,
        rewrite: path => path.replace(/^\/analysis/, '/analysis')
      },
      '/shortWarn': {
        target: 'http://10.226.107.37:8089/', //现场
        // target: 'http://101.126.153.10:9090/', //本地
        changeOrigin: true,
        rewrite: path => path.replace(/^\/shortWarn/, '/shortWarn')
      }
    }
  },
  build: {
    sourcemap: true,
  }
})
